package com.allwees.bs.module.core.datapermission;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.allwees.bs.module.core.datapermission.dao.PermissionRuleDao;
import com.allwees.bs.module.core.datapermission.entity.PermissionRule;
import com.allwees.core.common.constant.EStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

/**
 * RuleCache
 *
 * @author yangylsky
 * @since 2019-12-28
 *
 */
@Component
public class RuleCache {
	@Autowired
	private PermissionRuleDao permissionRuleDao;

	static final List<PermissionRule> RULES = new ArrayList<>();

	@PostConstruct
	private void init() {
		reloadCache();
	}

	public void reloadCache() {
		RULES.clear();

		List<PermissionRule> rules = permissionRuleDao.selectList(new QueryWrapper<PermissionRule>().eq("status", EStatus.NORMAL.value()));
		RULES.addAll(rules);
	}
}
